package com.zwz.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zwz.bean.UserLoginInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper //标记mapper文件位置，否则在Application.class启动类上配置mapper包扫描
@Repository
public interface UserLoginDao extends BaseMapper<UserLoginInfo> {
    /**
     * 查询用户名是否存在，若存在，不允许注册
     * 注解@Param(value) 若value与可变参数相同，注解可省略
     * 注解@Results  列名和字段名相同，注解可省略
     * @param username
     * @return
     */
    @Select(value = "select username,password from user_login where username=#{username}")
    UserLoginInfo findUserByName(String username);

    /**
     * 注册  插入一条user记录
     * @param login
     * @return
     */
    @Insert("insert into user_login values(#{id},#{username},#{password})")
    //加入该注解可以保存对象后，查看对象插入id
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void regist(UserLoginInfo login);

    /**
     * 登录
     * @param login
     * @return
     */
    @Select("select id from user_login where username = #{username} and password = #{password}")
    Integer login(UserLoginInfo login);


    @Insert("insert into userinfo values(null,null,null,null,null,#{id})")
    void addUserInfo(Integer id);

    @Delete("delete from userinfo where id = #{id}")
    int deleteUserInfo(Integer id);
}
